package com.william.jdbcplus.core.dialect.ddl.table;

import com.william.jdbcplus.common.entity.Entity;
import com.william.jdbcplus.core.meta.TableHelperUtil;
import com.william.jdbcplus.core.meta.TableInfo;
import com.william.jdbcplus.core.toolkit.StringPool;

/**
 * 表接口
 *
 * @author william
 */
public interface ITable {

    /**
     * 创建表
     *
     * @param clazz
     * @param <M>
     * @return
     */
    <M extends Entity> String create(Class<M> clazz);

    /**
     * 清空表数据
     *
     * @param clazz
     * @param <M>
     * @return
     */
    default <M extends Entity> String delete(Class<M> clazz) {
        TableInfo tableInfo = TableHelperUtil.getTableInfo(clazz);
        String tableName = tableInfo.getTableName();
        StringBuffer sql = new StringBuffer();
        sql.append(StringPool.NEWLINE).append(" delete from ").append(tableName).append(";");
        return sql.toString();
    }

    /**
     * 删除表
     *
     * @param clazz
     * @param <M>
     * @return
     */
    default <M extends Entity> String drop(Class<M> clazz) {
        TableInfo tableInfo = TableHelperUtil.getTableInfo(clazz);
        String tableName = tableInfo.getTableName();
        StringBuffer sql = new StringBuffer();
        sql.append(StringPool.NEWLINE).append(" drop table ").append(tableName).append(";");
        return sql.toString();
    }
}
